package h0721;

import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 判断字符串子序列
 * @date 2024/7/21 22:22
 */
public class DetermineTheSubsequenceOfAString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String target = sc.nextLine();
        String source = sc.nextLine();
        int resIndex = getLastIndex(target, source);
        System.out.println(resIndex);
    }

    private static int getLastIndex(String target, String source) {
        int ans = -1; //起始是-1

        int targetLen = target.length();
        int sourceLen = source.length();
        if (target.isEmpty() || targetLen > sourceLen) {
            return ans;
        }

        int j = targetLen - 1;
        //从末尾向头遍历   TODO 反向遍历
        for (int i = sourceLen - 1; i >= 0; i--) {

            if (source.charAt(i) == target.charAt(j)) {
                j--;
            }
            if (j<0){
                ans=i;
                break;
            }

        }
        return ans;
    }
}
